import axios from 'axios'
import apiUrls from 'common/api-urls'
import { setHttpHeaderCookie, headerToken } from 'common/axio-decorate'
import { setItem } from 'common/storage'
import { setTokenToCookie } from 'common/auth'

export function userLogin(params) {
  params = JSON.parse(JSON.stringify(params))
  return axios.post(apiUrls.userLogin, params)
}

export function setUserInfoToCache(userInfo) {
  const { token, userId, name } = userInfo

  setHttpHeaderCookie(token)
  setTokenToCookie(token)
  setItem('userInfo', { userId, name, userName: name, ...userInfo })
}

export function getCourtomer(data, token) {
  return axios.get(`${apiUrls.getCourtomer}/${data.id}`, {
    params: data,
    headers: {
      [headerToken]: token
    }
  })
}

export function getAuthInfo(token) {
  return axios.get(apiUrls.getAuthInfo, {
    params: {},
    headers: {
      [headerToken]: token
    }
  })
}
